#ifndef SORTED_ARRAY_H
#define SORTED_ARRAY_H

#include <iostream>
#include <iomanip>

using namespace std;

typedef float data_t;

//+-----------------------------------------------------
//| Module:      array_insert
//| Description: Insert one value in a sorted array.
//| Input:       - list:       The array
//|              - space_used: The number of used elements in the array
//|              - value:      The value to insert
//| Result:      The value is inserted at the sorted position
//| Conditions:  'list' is assumed to be sorted before insert
//|              'list' have enough space for at least one extra value
//|              'list' remain sorted after the operation
//+-----------------------------------------------------
void array_insert(data_t list[], int& space_used, data_t value);

//+-----------------------------------------------------
//| Module:      array_find
//| Description: Find at which index some value is found
//| Input:       - list:       The array
//|              - space_used: The number of used elements in the array
//|              - value:      The value to find
//| Result:      The first index containing 'value' is returned
//|              -1 is returned if 'value' was not found
//| Conditions:  'list' is assumed to be sorted
//+-----------------------------------------------------
int array_find(data_t list[], int& space_used, data_t value);

//+-----------------------------------------------------
//| Module:      array_remove
//| Description: Remove one value from a soreted array.
//| Input:       - list:       The array
//|              - space_used: The number of used elements in the array
//|              - index:      The index to remove
//| Result:      The value at 'index' is removed
//| Conditions:  'list' remain sorted after the operation
//|              'index' is assumed to exist
//+-----------------------------------------------------
void array_remove(data_t list[], int& space_used, int index);

//+-----------------------------------------------------
//| Module:      array_copy
//| Description: Copy all elements from src_list to dst_list
//| Input:       The source and destination array
//| Result:      The arrays contain identical data
//|              The arrays have the same number of elements
//| Conditions:  The destination array is assumed to be large
//|              enough to hold all values of the source array
//+-----------------------------------------------------
void array_copy(data_t dst_list[], data_t src_list[], 
                int& dst_space_used, int src_space_used);

//+-----------------------------------------------------
//| Module:      array_print
//| Description: Display all values in the array
//| Input:       Output stream, array, and number of elements used
//| Result:      Output to the stream with each number using 4
//|              character ositions
//| Conditions:  
//+-----------------------------------------------------
void array_print(ostream& out, data_t list[], int space_used);

#endif
